<?php


namespace addons\official\controller\api;

use addons\official\model\OfficialBanners;
use addons\official\model\OfficialCategory;

/**
 * 首页接口
 * @package addons\official\controller\api
 */
class Index extends BaseApi
{
    protected $noNeedLogin = ['*'];




    /**
     * 获取首页所有数据
     * @ApiMethod   (POST)
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturnParams   (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据返回")
     * @ApiReturn   ({
        "code": 1,
        "msg": "查询成功",
        "time": "1634701192",
        "data": "数据过多，请查询数据库对比字段"
     })
     */
    public function index()
    {
        //产品展示
        $new_list = $this->getFatherIsSon(9, 4, 10, 8);
        //服务范围
        $fuwu = $this->getOneCategoryIsData(19, 3);
        //新闻资讯
        $information = $this->getFatherIsSon(6, 2, 8, 10);
        //我们的客户
        $kehu = $this->getOneCategoryIsData(20, 9);
        //集合
        $data = array(
            'new_list'=>$new_list,
            'fuwu'=>$fuwu,
            'information'=>$information,
            'kehu'=>$kehu,
        );
        //返回结果
        $this->success(__api('','The query is successful'),$data);
    }


    /**
     * 获取所有轮播图
     * @ApiMethod   (POST)
     * @ApiParams   (name="sid", type="integer", required=false, description="栏目id")
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturnParams   (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据返回")
     * @ApiReturn   ({
        "code": 1,
        "msg": "查询成功",
        "time": "1634701192",
        "data": [
            {
                "id": "ID",
                "admin_id": "管理员ID",
                "official_category_ids": "栏目共有",
                "title": "标题",
                "image": "图片",
                "url": "跳转地址",
                "is_index": "是否显示在首页:0=不显示,1=显示",
                "status": "状态:0=下架,1=上架",
                "language": "语言:1=English,2=简体中文",
                "weigh": "权重/排序",
                "createtime": "创建时间",
                "updatetime": "更新时间",
                "deletetime": "删除时间"
            }
        ]
     })
     */
    public function getAllBanners()
    {
        $cid = (int)input('param.sid');
        $banners = (new OfficialBanners())
            ->where('status', 1)
            ->where('language', $this->language)
            ->where('deletetime', null);
        //栏目id
        if ($cid) {
            $banners = $banners->where("FIND_IN_SET(" . $cid . ",official_category_ids)");
        } else {
            $banners = $banners->where('is_index', 1);
        }
        //查询
        $banners = $banners
            ->order('weigh', 'desc')
            ->select();
        $this->success(__api('','The query is successful'), $banners);
    }


    /**
     * 获取配置项全部信息
     * @ApiMethod   (POST)
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturnParams   (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据返回")
     * @ApiReturn   ({
        "code": 1,
        "msg": "查询成功",
        "time": "1634647881",
        "data": {
            "变量名": {
                "id": "ID",
                "name": "变量名",
                "group": "分组",
                "title": "变量标题",
                "tip": "变量描述",
                "type": "类型:string,text,int,bool,array,datetime,date,file",
                "value": "变量值",
                "content": "变量字典数据",
                "rule": "验证规则",
                "extend": "扩展属性",
                "setting": "配置"
            }
        }
     })
     */
    public function getConfig(){
        $official_config_url = ADDON_PATH . 'official' . DS . 'controller' . DS . 'common' . DS . 'official_config.php';
        if (!file_exists($official_config_url)) {
            $this->error(__api('','Your configuration item file was not generated'));
        }
        $config_all = include $official_config_url;
        $this->success(__api('','The query is successful'),$config_all);
    }


}